<?php

    // 每一行代码结束都必须加分号

    header('content-type:text/html;charset-utf-8') ;

    // 数据库连接

    $host = 'localhost:3306' ;
    $name = $pwd = 'root' ;
    $dbname = 'day24' ;
    $conn = mysqli_connect($host , $name , $pwd , $dbname) ;
    // 判断数据库是否连接成功
    if(!$conn) {
        die('数据库连接失败');
    }


    // 删除  根据用户名和商品id 
    $uname = $_POST['username'] ;
    $id = $_POST['id'] ;

    $obj = [] ;

    if($uname && $id) {
        
        $sql = "delete from cart where username = '$uname' and goods_id = $id" ;
        mysqli_query($conn , $sql) ;
        $rows = mysqli_affected_rows($conn) ;
        if($rows > 0) {
            $obj['status'] = true ;
            $obj['msg'] = '删除成功';
        } else {
            $obj['status'] = false ;
            $obj['msg'] = '删除失败';
        }
    } else {
        $obj['status'] = false ;
        $obj['msg'] = '前端数据有误';
    }




    echo(json_encode($obj , JSON_UNESCAPED_UNICODE)) ;

